package com.voltmao.controller.module.sys;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.voltmao.service.application.sys.RegionServiceImpl;
import com.voltmao.webpro.frame.analyze.DTOSmith;
import com.voltmao.webpro.frame.dto.ApiResult;
import com.voltmao.webpro.frame.dto.DataPage;
import com.voltmao.webpro.frame.dto.status.Constants;
import com.voltmao.webpro.utils.http.HttpRequestUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 区域控制层
 *
 * @author zhanglin
 * @date 2018/04/14
 */
@Controller
@RequestMapping(value = "/module/sys/region")
public class RegionController {

    @Autowired
    RegionServiceImpl regionService;

    @ResponseBody
    @RequestMapping(value = "/apiRegion.json", method = RequestMethod.POST)
    public ApiResult getDictionary(HttpServletRequest request){
        /*
         * 根据pcode拿到所有的记录
         */
        return new DTOSmith(request).builderApiResult((request1, apiResult)->{
            Map<String, Object> params = HttpRequestUtil.getParameterMap(request1);
            try {
                DataPage results = regionService.selectRegionDataPage(params);
                apiResult.setStatus(Constants.SUCCESS);
                return results;
            } catch (Exception e){
                apiResult.setStatus(Constants.FAIVAL);
                return null;
            }
        });

    }
}
